<?php

class Db_Setup_VoucherGroups extends Common {
    protected static $tableName = TAB_VOUCHER_GROUPS;
    protected static $dbFields = array(
        'id',
        'vg_name',
        'vg_type',
        'vg_fixed_amount',
        'vg_percentage',
        'vg_min_order_value',
        'vg_unique',
        'deleted'
    );

    public $objectArray;

    public $id;
    public $vg_name;
    public $vg_type;
    public $vg_fixed_amount;
    public $vg_percentage;
    public $vg_min_order_value;
    public $vg_unique;
    public $deleted;

    function __construct($value=NULL, $fieldName=NULL) {
        parent::__construct($value, $fieldName);
    }


    public static function getTotalVoucherGroups($sqlCondition = '1=1') {
        if (empty($sqlCondition)) {
            $sqlCondition = '1=1';
        }
        $sql = "SELECT COUNT(DISTINCT `vg`.`id`) FROM ?f vg
				WHERE `vg`.`deleted` = 0 AND {$sqlCondition}";
        return self::$DB->selectCell($sql, self::$tableName);
    }

    public static function getAllVoucherGroupsPerPage($limit, $searchSql = '', $orderBy = '') {
        if (empty($searchSql)) {
            $searchSql = '1=1';
        }

        if (empty($orderBy)) {
            $orderBy = ' ORDER BY `vg`.`id` ASC ';
        }
        $sql = "SELECT `vg`.* FROM ?f vg
				WHERE `vg`.`deleted` = 0 AND {$searchSql} {$orderBy} {$limit}";

        return self::$DB->select($sql, self::$tableName);
    }
}